package Thread_Pool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Thread_PoolDemo {

	public static void main(String[] args) throws Exception {
		ExecutorService pool = Executors.newFixedThreadPool(2);
		Future<Integer> future = pool.submit(new MyCallable(5));
		Future<Integer> future2 = pool.submit(new MyCallable(4));
		Integer integer = future.get();
		Integer integer2 = future2.get();
		System.out.println(integer);
		System.out.println(integer2);
	}
}

class MyCallable implements Callable<Integer> {
	private int num;
	public MyCallable(int num){
		this.num=num;
	}
	public Integer call(){
		return jieCheng(num);
	}
	public int jieCheng(int num) {
		if(num==0|num==1){
			return 1;
		}else if(num<0) {
			return -1;
		}else{
			return jieCheng(num-1)*num;
		}
	}
}
